/**
 * Created by Whale on 2017/9/27.
 */
var webpack = require('webpack');
var ExtractTextPlugin =require("extract-text-webpack-plugin");


var commonAlias = {
    "bootstrapCss": __dirname + "/bootstrap/css/bootstrap.css",
    "bootstrapJs": __dirname + "/bootstrap/js/bootstrap.js",
    "jquery": __dirname + "/js/jquery-1.11.0.min.js",
    "file-api": __dirname + "/node_modules/fileapi/dist/fileapi.min.js",
    "vue": __dirname + "/node_modules/vue/dist/vue.runtime",
    "Vue": "vue",
    "vue-router":__dirname + "/node_modules/vue-router/dist/vue-router.js",
}
var alias = {
    "Swiper":__dirname + "/js/swiper/swiper.min.js",
    "Swiper.css":__dirname + "/js/swiper/swiper.min.css",
    "vue-infinite-scroll":__dirname + "/node_modules/vue-infinite-scroll/vue-infinite-scroll.js",
}
module.exports = {
    //插件项
    plugins: [
        new webpack.optimize.CommonsChunkPlugin({
            name: ["common"],
            filename: "[name].[chunkhash:8].js",
            minChunks: Infinity,
        }),
        new ExtractTextPlugin(
            "[name].[contenthash:8].css",
            {allChunks: true}
        ),
        new webpack.ProvidePlugin({
            $: "jquery",
            jQuery: "jquery",
            Vue: "Vue",
        }),
        new webpack.DefinePlugin({
            __DEBUG__: false,
            'process.env': {
                NODE_ENV: '"production"'
            },
        }),
        new webpack.optimize.UglifyJsPlugin({
            compress:{
                warnings: false,
                drop_debugger: true,
                drop_console: true
            }
        })
    ],
    //页面入口文件配置
    entry: {
        'main' : './main/main.js',
        'common': Object.keys(commonAlias),
    },
    //入口文件输出配置
    output: {
        path: __dirname + '/dist/',
        publicPath: '/dist/',
        filename: '[name].[chunkhash:8].js',
    },
    module: {
        //加载器配置
        loaders: [
            { test: /\.css$/, loader: ExtractTextPlugin.extract("style-loader", "css-loader?sourceMap") },
            { test: /\.less$/, loader: ExtractTextPlugin.extract("style-loader", "css-loader!less-loader") },
            { test: /\.(gif|jpg|png|jpeg|webp)\??.*$/, loader: 'url-loader?limit=20000&name=[name].[hash:8].[ext]'},
            { test: /\.(woff|svg|eot|ttf)\??.*$/, loader: 'url-loader?limit=1&name=[name].[hash:8].[ext]'},
            { test: /\.vue$/, loader: 'vue-loader'},
        ]
    },
    vue: {
        loaders: {
            css: ExtractTextPlugin.extract("style-loader", "css-loader?sourceMap"),
            less: ExtractTextPlugin.extract("style-loader", "css-loader!less-loader")
        }
    },
    resolve: {
        alias: Object.assign(commonAlias, alias)
    },
};